//package cn.gwm.flink.streaming.strategy.vehiclepredict;
//
//import com.alibaba.fastjson.JSONObject;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.flink.api.common.functions.MapFunction;
//import org.apache.flink.api.common.typeinfo.Types;
//import org.apache.flink.core.fs.Path;
//import org.apache.flink.formats.parquet.ParquetWriterFactory;
//import org.apache.flink.streaming.api.datastream.DataStream;
//import org.apache.flink.streaming.api.functions.sink.filesystem.StreamingFileSink;
//import org.apache.flink.streaming.api.functions.sink.filesystem.rollingpolicies.OnCheckpointRollingPolicy;
//
//import java.io.Serializable;
//import java.time.ZoneId;
//
///**
// * @author : GW00280745
// * @date : 2022/11/23 13:44
// * @description :
// */
//public class ParquetFileSink implements Serializable {
//    /**
//     * @description:
//    需要额外添加依赖信息
//    parquet依赖：
//    <dependency>
//    <groupId>org.apache.flink</groupId>
//    <artifactId>flink-avro</artifactId>
//    <version>${flink.version}</version>
//    </dependency>
//    <dependency>
//    <groupId>org.apache.flink</groupId>
//    <artifactId>flink-parquet_2.11</artifactId>
//    <version>1.10.0</version>
//    </dependency>
//    <dependency>
//    <groupId>org.apache.parquet</groupId>
//    <artifactId>parquet-avro</artifactId>
//    <version>1.10.0</version>
//    </dependency>
//    <dependency>
//    <groupId>org.apache.avro</groupId>
//    <artifactId>avro</artifactId>
//    <version>1.10.0</version>
//    </dependency>
//     **/
//    public StreamingFileSink<HiveColumnsChargePredict> fileSinkWithSnappyCompress(String outputPath){
//        ParquetWriterFactory<HiveColumnsChargePredict> parquetWriterFactory = HdfsDataCompress.forReflectRecord(HiveColumnsChargePredict.class);
//        ChargeBucketAssigner<HiveColumnsChargePredict> bucketAssigner =
//                new ChargeBucketAssigner<>("yyyy-MM-dd", ZoneId.of("Asia/Shanghai"));
//
//        StreamingFileSink<HiveColumnsChargePredict> sink = StreamingFileSink
//                .forBulkFormat(new Path(outputPath), parquetWriterFactory)
//                .withBucketAssigner(bucketAssigner)
//                .withRollingPolicy(OnCheckpointRollingPolicy.build())
//                .build()
//                ;
//        return sink;
//    }
//    public void parquetFile2Hive(DataStream batterIntervalStream, String path){
//        StreamingFileSink<HiveColumnsChargePredict> fileSink = fileSinkWithSnappyCompress(path);
//        //parquetSink
//        batterIntervalStream.map(new MapFunction() {
//            private Integer intVal(JSONObject jsonObject,String field){
//                String string = jsonObject.getString(field);
//                if (StringUtils.isBlank(string)){
//                    return -999999;
//                }
//                try {
//                    return Integer.parseInt(string);
//                }catch (Exception e){
//                    return -999999;
//                }
//            }
//            private Float floatVal(JSONObject jsonObject,String field){
//                String string = jsonObject.getString(field);
//                if (StringUtils.isBlank(string)){
//                    return -999999.0f;
//                }
//                try {
//                    return Float.parseFloat(string);
//                }catch (Exception e){
//                    return -999999.0f;
//                }
//            }
//            private Long longVal(JSONObject jsonObject,String field){
//                String string = jsonObject.getString(field);
//                if (StringUtils.isBlank(string)){
//                    return -999999L;
//                }
//                try {
//                    return Long.parseLong(string);
//                }catch (Exception e){
//                    return -999999L;
//                }
//            }
//            private String strVal(JSONObject jsonObject,String field){
//                String s = jsonObject.getString(field);
//                if (StringUtils.isBlank(s)){
//                    return "-999999";
//                }
//                return s;
//            }
//            @Override
//            public Object map(Object value) throws Exception {
//                try {
//                    JSONObject jsonObject = (JSONObject) value;
//                    HiveColumnsChargePredict data = new HiveColumnsChargePredict();
//                    data.setBMS_BattCurr_RM(floatVal(jsonObject,"BMS_BattCurr_RM"));
//                    data.setBMS_ChrgSts(intVal(jsonObject,"BMS_ChrgSts"));
//                    data.setBMS_ChrgTime(intVal(jsonObject,"BMS_ChrgTime"));
//                    data.setBMS_CoolReq(intVal(jsonObject,"BMS_CoolReq"));
//                    data.setBMS_DCChrgConnect(intVal(jsonObject,"BMS_DCChrgConnect"));
//                    data.setBMS_HeatReq(intVal(jsonObject,"BMS_HeatReq"));
//                    data.setBMS_RMC_ModuleTempMax(intVal(jsonObject,"BMS_RMC_ModuleTempMax"));
//                    data.setBMS_RMC_ModuleTempMin(intVal(jsonObject,"BMS_RMC_ModuleTempMin"));
//                    data.setBMS_SOC(floatVal(jsonObject,"BMS_SOC"));
//                    data.setBMS_SOH(intVal(jsonObject,"BMS_SOH"));
//                    data.setOBC_ConnectSts_EV(intVal(jsonObject,"OBC_ConnectSts_EV"));
//                    data.setBatter_capcity(strVal(jsonObject,"batter_capcity"));
//                    data.setBatter_type(strVal(jsonObject,"batter_type"));
//                    data.setBrand(strVal(jsonObject,"brand"));
//                    data.setDeviceId(strVal(jsonObject,"deviceId"));
//                    data.setBatt_soc_range(strVal(jsonObject,"batt_soc_range"));
//                    data.setBatt_tem_range(strVal(jsonObject,"batt_tem_range"));
//                    data.setBatter_interval_point(intVal(jsonObject,"batter_interval_point"));
//                    data.setBatter_map_value(floatVal(jsonObject,"batter_map_value"));
//                    data.setBatter_value_err(intVal(jsonObject,"batter_value_err"));
//                    data.setCharge_frb(strVal(jsonObject,"charge_frb"));
//                    data.setCharge_id(strVal(jsonObject,"charge_id"));
//                    data.setCharge_init_point(intVal(jsonObject,"charge_init_point"));
//                    data.setDc_obc_sts(intVal(jsonObject,"dc_obc_sts"));
//                    data.setEsti_point_flag(intVal(jsonObject,"esti_point_flag"));
//                    data.setEsti_temp(floatVal(jsonObject,"esti_temp"));
//                    data.setEsti_time(floatVal(jsonObject,"esti_time"));
//                    data.setHeat_sts(intVal(jsonObject,"heat_sts"));
//                    data.setItem_time(longVal(jsonObject,"item_time"));
//                    data.setMove_avg_point(floatVal(jsonObject,"move_avg_point"));
//                    data.setMove_avg_process(strVal(jsonObject,"move_avg_process"));
//                    data.setPredict_time(strVal(jsonObject,"predict_time"));
//                    data.setPredict_time_v1(strVal(jsonObject,"predict_time_v1"));
//                    data.setSoc_interval_point(intVal(jsonObject,"soc_interval_point"));
//                    data.setSource(intVal(jsonObject,"source"));
//                    data.setTemp(intVal(jsonObject,"temp"));
//                    data.setTempAcc_batter_range(strVal(jsonObject,"tempAcc_batter_range"));
//                    data.setTemp_acc(floatVal(jsonObject,"tempAccVal"));
//                    data.setTemp_acc_err(intVal(jsonObject,"temp_acc_err"));
//                    data.setTemp_interval_point(intVal(jsonObject,"temp_interval_point"));
//                    data.setVehicletype(strVal(jsonObject,"vehicletype"));
//                    data.setTempAcc_temp_range(strVal(jsonObject,"tempAcc_temp_range"));
//                    return data;
//                }catch (Exception e){
//                    e.printStackTrace();
//                }
//                return null;
//            }
//        }).returns(Types.GENERIC(HiveColumnsChargePredict.class))
//                .addSink(fileSink)
//                .name("parquetFile2Hive");
//    }
//
//}
